package com.caration.shell.workspace2D;

import java.util.ArrayList;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import com.caration.shell.cr3d.SharedData;

public class ShellAppInfo {
	public CharSequence mTitle;
	public Intent mIntent;
	public ComponentName mComponentName;
	public int mIconId;
	public int f;
	public boolean isSystemApp = true;
	public boolean h = false;
	public boolean i = false;
	public long mFirstInstallTime;
	public boolean k = false;

	public ShellAppInfo(ResolveInfo resolveinfo) {
		resolve(resolveinfo);
	}

	public ShellAppInfo(CharSequence charsequence, String pkg, String cls,
			Intent intent, int l) {
		mTitle = charsequence;
		mComponentName = new ComponentName(pkg, cls);
		mIntent = intent;
		f = l;
	}

	public final void resolve(ResolveInfo resolveinfo) {
		if (resolveinfo.activityInfo.icon != 0)
			mIconId = resolveinfo.activityInfo.icon;
		else
			mIconId = resolveinfo.activityInfo.applicationInfo.icon;
		mComponentName = new ComponentName(
				resolveinfo.activityInfo.applicationInfo.packageName,
				resolveinfo.activityInfo.name);
		mIntent = new Intent(Intent.ACTION_MAIN);
		mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
		mIntent.setComponent(mComponentName);
		mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
				| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
		PackageManager packageManager = SharedData.getContext()
				.getPackageManager();
		mTitle = resolveinfo.loadLabel(packageManager).toString();
		if (mTitle == null)
			mTitle = resolveinfo.activityInfo.name;
		if (android.os.Build.VERSION.SDK_INT >= 9) {
			try {
				mFirstInstallTime = packageManager.getPackageInfo(
						resolveinfo.activityInfo.applicationInfo.packageName,
						128).firstInstallTime;
			} catch (Exception exception) {
				exception.printStackTrace();
			}
		}
		if ((ApplicationInfo.FLAG_UPDATED_SYSTEM_APP & resolveinfo.activityInfo.applicationInfo.flags) != 0
				|| (ApplicationInfo.FLAG_SYSTEM & resolveinfo.activityInfo.applicationInfo.flags) == 0) {
			isSystemApp = false;
		}
	}

	public final String toString() {
		return "LauncherAppInfo(mTitle=" + mTitle + ")";
	}
}
